package day_2022_7_to_8.day48;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author haomin
 * @date 2022/08/06 18:18
 **/
public class Day22_2_Num17_letterCombinations {
    public static void main(String[] args) {
        String str = "23";
        letterCombinations(str);
        System.out.println(res.toString());
    }

    public static Map<Character,String> map = new HashMap<>();
    public static List<String> res = new ArrayList<>();
    public static List<String> letterCombinations(String digits) {
        if(digits.length() == 0) return res;
        map.put('2',"abc");map.put('3',"def");map.put('4',"ghi");
        map.put('5',"jkl");map.put('6',"mno");map.put('7',"pqrs");
        map.put('8',"tuv");map.put('9',"wxyz");

        StringBuilder sb = new StringBuilder();
        dfs(digits,0,sb);
        return res;
    }
    private static void dfs(String digits, int index, StringBuilder sb){
        if(index == digits.length()){
            res.add(sb.toString());
            return;
        }
        String str = map.get(digits.charAt(index));
        System.out.println(str);
        for(int i = 0;i < str.length();i++){
            sb.append(str.charAt(i));
            dfs(digits,index+1,sb);
            sb.deleteCharAt(sb.length()-1);
        }
    }
}